package p;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import model.StringPosVec;
import model.StringAnalyser;

import org.junit.Test;

public class StringTesting {

	@Test
	public final void cutVoid() {
		String x = "  abc  =  123  ";
		assertTrue(StringAnalyser.getIdInString(x).equals("abc"));
		assertTrue(StringAnalyser.getTermInString(x).equals("123"));
	}

	@Test
	public final void innerTermVoid() {

		String x;
		StringPosVec pos;

		x = "((abc+7)+(c))";
		System.out.println(x);
		pos = StringAnalyser.getFirstInnerTermPos(x);
		System.out.println(pos);
		assertTrue(pos.start == 1 && pos.end == 7);

		x = "a+b";
		System.out.println(x);
		pos = StringAnalyser.getFirstInnerTermPos(x);
		System.out.println(pos);
		assertTrue(pos==null);
		
		x = "((b) +x)";
		pos = StringAnalyser.getFirstInnerTermPos(x);
		System.out.println(x);
		System.out.println(pos);
		x=StringAnalyser.replacePart(x, "@1", pos);
		System.out.println(x);
		assertTrue(StringAnalyser.getTermInString(x).equals("(@1 +x)"));

		x = "( {2b} +x)";
		System.out.println(x);
		x = StringAnalyser.getOptimizedTerm(x);
		System.out.println(x);
		assertTrue(StringAnalyser.getTermInString(x).equals("((2*b)+x)"));
		
		x = "a+ b ";
		System.out.println(x);
		x = StringAnalyser.getOptimizedTerm(x);
		System.out.println(x);
		assertTrue(StringAnalyser.getTermInString(x).equals("a+b"));

		x = "a  + b ";
		System.out.println(x);
		int y = StringAnalyser.getOperatorPos(x);
		System.out.println(y);
		assertTrue(y==3);
		
		x = "a+b";
		System.out.println(x);
		y=StringAnalyser.getVarPosLeftFrom(x, 1);
		System.out.println(y);
		assertTrue(y==0);
		
		x = "a+b";
		System.out.println(x);
		y=StringAnalyser.getVarPosRightFrom(x, 1);
		System.out.println(y);
		assertTrue(y==2);
		
		x = "a+baa+daa+e";
		System.out.println(x);
		y=StringAnalyser.getVarPosLeftFrom(x, 5);
		System.out.println(y);
		assertTrue(y==2);
		
		x = "a+baa+daa+e";
		System.out.println(x);
		y=StringAnalyser.getVarPosRightFrom(x, 5);
		System.out.println(y);
		assertTrue(y==8);
		
	}

	@Test
	public final void removeTest() {
		String x = "abc";
		System.out.println(x);
		x=StringAnalyser.remove(x, 0);
		System.out.println(x);
		assertTrue(StringAnalyser.getTermInString(x).equals("bc"));
	}
	
	@Test
	public final void getVarListVoid() {
		String x = "((abc+7)+(7c))";
		System.out.println(x);
		ArrayList y;
		y = StringAnalyser.getElementsInTermList(x);
		System.out.println(y);
		assertTrue(y.size() == 3);

		x = "((x+x)+(X))";
		System.out.println(x);
		y = StringAnalyser.getElementsInTermList(x);
		System.out.println(y);
		assertTrue(y.size() == 3);

		y = StringAnalyser.getVarsList(y);
		System.out.println(y);
		assertTrue(y.size() == 2);
		
		x = "x+y";
		System.out.println(x);
		y = StringAnalyser.getElementsInTermList(x);
		System.out.println(y);
		assertTrue(y.size() == 2);

		y = StringAnalyser.getVarsList(y);
		System.out.println(y);
		assertTrue(y.size() == 2);

	}

}